/*
 * Copyright (C) 2008,2009,2010,2011  Paulo Cesar Pereira de Andrade.
 *
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * Authors:
 *	Paulo Cesar Pereira de Andrade
 */

#ifndef _edefs_h
#define _edefs_h

#if defined(__GNUC__)
#  define noreturn		__attribute__ ((noreturn))
#  define printf_format(f, v)	__attribute__ ((format (printf, f, v)))
#  define maybe_unused		__attribute__ ((unused))
#  define unlikely(exprn)	__builtin_expect(!!(exprn), 0)
#  define likely(exprn)		__builtin_expect(!!(exprn), 1)
#  if (__GNUC__ >= 4)
#    define PUBLIC		__attribute__ ((visibility("default")))
#    define HIDDEN		__attribute__ ((visibility("hidden")))
#  else
#    define PUBLIC		/**/
#    define HIDDEN		/**/
#  endif
#else
#  define noreturn		/**/
#  define printf_format(f, v)	/**/
#  define maybe_unused		/**/
#  define unlikely(exprn)	exprn
#  define likely(exprn)		exprn
#  define PUBLIC		/**/
#  define HIDDEN		/**/
#endif

#define real(dd)		__real__ dd
#define imag(dd)		__imag__ dd

#define enew(pointer, type)						\
    enew_object((eobject_t *)pointer, t_##type, sizeof(e##type##_t))

#define esize(vector)		(sizeof(vector) / sizeof((vector)[0]))

#define null			((eobject_t)0)
#define eof			-1
#define false			0
#define true			1

#ifndef BUFSIZ
#define BUFSIZ			8192
#endif

#define MININT			(1LL << 63)
#define MININT32		(1 << 31)

#define ALIGN64			__WORDSIZE == 64

/*
 * Stream defines
 */
#define S_read			(1 << 0)
#define	S_write			(1 << 1)
#define S_io			(S_read | S_write)
#define S_append		(1 << 2)
#define S_nonblock		(1 << 3)
#define S_buffered		(1 << 4)
#define S_unbuffered		(1 << 5)
#define S_source		(1 << 6)

/*
 * Hash defines
 */
#define H_string		0
#define H_pointer		1

/*
 * Lambda defines
 */
#define L_result		(1 << 0)
#define L_varargs		(1 << 1)
#define L_builtin		(1 << 2)

/* define to truth value to not recognize:
 * "foo
 * bar"
 * as:
 * "foo\nbar"
 * but require it as:
 * "foo\n\
 * bar"
 * this affects scan* builtin functions, and the default value (1)
 * matches C semantics
 */
#define NEWLINE_NEEDS_BACKSLASH	1

#define SUSPEND_SIGNAL		SIGUSR1
#define RESUME_SIGNAL		SIGUSR2

#endif /* _edefs_h */
